package com.wk.kxexamadminister.controller;

import com.wk.kxexamadminister.entity.ClassTable;
import com.wk.kxexamadminister.entity.Institute;
import com.wk.kxexamadminister.mapper.InstituteMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@Api(description = "x学院操作")
public class InstituteController {

    @Autowired
    private InstituteMapper instituteMapper;

    @ApiOperation("增加")
    @PostMapping("/addInstitute")
    public String addClass(Institute Institute){
        int insert = instituteMapper.insert(Institute);
        if(insert == 1) {
            return "redirect:/findAllInstitute";
        }
        return "error";
    }

    @ApiOperation("删除")
    @GetMapping("/delInstitute")
    @ResponseBody
    public String delClass(int iId){
        int i = instituteMapper.deleteById(iId);
        if(i == 1) {
            return "Success";
        }
        return "No";
    }

    @ApiOperation("修改")
    @GetMapping("/updateInstitute")
    public String updateClass(Institute institute){
        int i = instituteMapper.updateById(institute);
        if(i == 1) {
            return "redirect:/findAllInstitute";
        }
        return "error";
    }

    @ApiOperation("查找")
    @GetMapping("/findAllInstitute")
    public String findAll(Model model){
        List<Institute> allinstitute = instituteMapper.selectList(null);
        model.addAttribute("allinstitute",allinstitute);
        return "04-queryAllCollge";
    }




}
